package com.liwenfeng.bigevent.controller;

import com.liwenfeng.bigevent.pojo.Result;
import com.liwenfeng.bigevent.utils.AliOssUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
@CrossOrigin(origins = "*")
public class FileUploadController {
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws IOException {
//        file.transferTo(new File("D:\\code\\file\\"+ UUID.randomUUID().toString() +file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."))));
        String url = AliOssUtil.uploadFile((UUID.randomUUID().toString() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."))), file.getInputStream());
        return Result.success(url);
    }
}
